﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Pro.Common.IoC
{
    public class TypeSource : ITypeSource
    {
        private readonly IAssemblySource _assemblySource;

        public TypeSource(IAssemblySource assemblySource)
        {
            _assemblySource = assemblySource;
        }

        public IEnumerable<Type> GetTypes()
        {
            return _assemblySource
                .GetAssemblies()
                .SelectMany(assembly => assembly.GetTypes())
                .Where(type => type.IsPublic && !type.IsAbstract && type.IsClass);
        }
    }
}